# Maintainer: Timo Teräs <timo.teras@iki.fi>
_luaversions="5.1 5.2 5.3 5.4"

pkgname=lua-maxminddb
pkgver=0.1
pkgrel=3
pkgdesc="libmaxminddb bindings for Lua"
url="https://github.com/fabled/lua-maxminddb"
arch="all"
license="MIT"
makedepends="libmaxminddb-dev"
for _i in $_luaversions; do
	depends="$depends lua$_i-maxminddb"
	makedepends="$makedepends lua$_i-dev"
	subpackages="$subpackages lua$_i-maxminddb:_maxminddb_${_i/./_}"
done
source="$pkgname-$pkgver.tar.gz::https://github.com/fabled/lua-maxminddb/archive/v$pkgver.tar.gz"

prepare() {
	default_prepare

	# apply patches here
	for _i in $_luaversions; do
		cp -a "$builddir" "$srcdir"/build-$_i
	done
}

build() {
	for _i in $_luaversions; do
		cd "$srcdir"/build-$_i
		msg "build for Lua $_i"
		make LUA_PKG="lua$_i"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_split_maxminddb() {
	local _ver=$1
	pkgdesc="$pkgdesc $_ver"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends=""

	cd "$srcdir"/build-$_ver
	make install LUA_PKG="lua$_ver" DESTDIR="$subpkgdir"
}

for _i in $_luaversions; do
	eval "_maxminddb_${_i/./_}() { _split_maxminddb $_i; }"
done

sha512sums="37fb3e37e24dd6188a1d38945056acd8444d0963af5c53b3c3af51f02130d0eeeb2d32428fae9e75f55db49b7caefe557389f93e27208729222b1a91e63dff0a  lua-maxminddb-0.1.tar.gz"
